#ifndef STARLINE
#define STARLINE


#include <stdlib.h>

#include "Star.h"

class StarLine
{
private:
	Star* stars;
	int minimum_num_stars;
	int maximum_num_stars;

	bool vertical;
	int num_stars;
	float distance_between_stars;

public:
	/**
	 * CTOR
	 * accepts arguments:
	 * int minimum_Stars - minimum number of stars
	 * int maximum_Stars - maximum number of stars
	 * bool Vertical     - whether the star line will be vertical or horizontal
	 * float dis_between_stars - distance between each star (will be in a call to glTranslatef)
	 */
	StarLine(int minimum_Stars, int maximum_Stars, bool Vertical, float dist_between_stars)
	{
		vertical = Vertical;
		distance_between_stars = dist_between_stars;

		minimum_num_stars = minimum_Stars;
		maximum_num_stars = maximum_Stars;

		//if minimum > maximum, there's a problem...
		if(minimum_num_stars > maximum_num_stars)
		{
			//defaults to a minimum value of 3 and a maximum value of 10
			minimum_num_stars = 3;
			maximum_num_stars = 10;
		}
		num_stars = rand() % maximum_num_stars + minimum_num_stars;

		try {
		stars = new Star[num_stars];
		}
		//std::bad_alloc is thrown on allocation failure
		catch(std::bad_alloc)
		{
			//BAD ALLOCATION- HANDLE ERROR
		}


	}

	/**
	 * Destructor
	 */
	~StarLine()
	{
		delete[] stars;
	}


	/**
	 * draw function
	 * Loops through every star in the array, translating and then drawing it
	 */
	void draw()
	{
		//if its a vertical starline...
		if(vertical)
		{
			for(int i = 0; i < num_stars; i++)
			{
				//translate on the Y axis
				glTranslatef(0, distance_between_stars, 0);
				stars[i].draw();
			}
		}
		//otherwise its horizontal
		else
		{
			for(int i = 0; i < num_stars; i++)
			{
				//translate on the X axis
				glTranslatef(distance_between_stars, 0, 0);
				stars[i].draw();
			}
		}
	}
};



#endif
